$(function () {
    $("input[name=taskType]").click(function () {
        $(".tasktype-list").hide();

        var t = ~~$(this).val();
        if (t == 1) {
            $(".taskType1 input[name=taskTypeItem]").eq(0).click();
            $(".taskType1").show();
        } else if (t == 2) {
            $(".taskType2 input[name=taskTypeItem]").eq(0).click();
            $(".taskType2").show();
        }
    });

    $("input[name=taskTypeItem]").on(
        "click change",
        function () {
            document.getElementById("server_striking").innerHTML = settingList[$(this).val()]["service_platform"];//$(this).val();



            $("input[name=shopId]").removeAttr("checked").attr("disabled",
                "disabled");
            var shopForm = $(this).attr('shopForm');
            // if (shopForm == 1) {
            //     $("input[name=shopId][shopForm=2]").removeAttr("disabled");
            // }
            $("input[name=shopId][shopForm=" + shopForm + "]").removeAttr(
                "disabled");
        });

    var validator = $("#form1").validate({
        validClass: 'checked',
        ignore: ":hidden", // 不验证的元素
        rules: {},
        unhighlight: function (element, errorClass, validClass) { // 验证通过
            $(element).tooltip('destroy').removeClass(errorClass);
        },
        errorPlacement: function (label, element) {
            $(element).tooltip('destroy'); /* 必需 */
            $(element).attr('title', $(label).text()).tooltip('show');
        },
        submitHandler: function (form) {
            var taskType = $("input[name=taskType]:checked").size();
            var taskTypeItem = $("input[name=taskTypeItem]:checked").size();
            if (!taskType || !taskTypeItem) {
                alert("请先选择任务类型");
                return;
            }

            var shops = $("input[name=shopId]").size();
            var shopcheck = $("input[name=shopId]:checked").size();
            if (shops) {
                if (shopcheck) {
                    // taskAdd();
                    $('#form1').preventDefault();
                    $('#form1').submit();
                    return true;
                } else {
                    alert("请选择店铺");
                }
            } else {
                alert("请添加店铺!");
            }
        },
        success: function (label) {
            label.html("&nbsp;").remove();
        }
    });
});

var bTemp = false;

function taskAdd() {
    if (bTemp) {
        return false;
    }
    bTemp = true;
    var data = $('#form1').serialize();
    Call.ajaxSend('task/edit.do', data, function (d) {
        if (d.success == true) {
            //var taskId = d.data.taskId;
            Call.httpLoad('/task/step2.html');
        } else {
            alert(d.msg);
        }
        bTemp = false;
    });
}